package com.xh.bgc.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.xh.bgc.services.userSearch.MySearchServices;
import com.xh.bgc.util.RadomNumber;

@RequestMapping(value = "/backstage")
@Controller
public class BackstageController {
	@Autowired
	private MySearchServices searchBiz;

	@ResponseBody
	@RequestMapping(value = "/mySearch", produces = "text/html;charset=UTF-8")
	public Object mySearch(Map<String, Object> map) {

		List<Map<String, Object>> list = searchBiz.mySearch();
		map.put("list", list);
		String data = JSON.toJSONString(list);

		return data;
	}

	/**
	 * 检索原始密码是否为空
	 * 
	 * @param phone
	 * @param password
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/search")
	public String searchByPhone(@RequestParam String phone,
			@RequestParam String password) {

		List<Map<String, Object>> list = searchBiz.search(phone, password);
		String json = JSON.toJSONString(list);
		return json;
	}

	/**
	 * 获取验证码
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/getRandom")
	public String getRandom() {
		RadomNumber rd = new RadomNumber();
		
		String random =rd.getRandom();
		System.out.println(random);
		String data = null;
		if (random != "" && !"".equals(random)) {
			data = JSON.toJSONString(random);
		}
		return data;
	}
	
	
	
	@RequestMapping(value="/upPassword")
	public String upPassword(@RequestParam String phone,@RequestParam String password,@RequestParam String password1){
int i=searchBiz.upPassword(phone,password,password1);
	
		return "redirect:/jsp/index.jsp";
		   
	}

}
